package com.longkey.workflow.client.property
{
	import com.longkey.workflow.client.constants.ElementType;
	import com.longkey.workflow.client.event.ElementEvent;
	import com.longkey.workflow.client.event.TemplateEvent;
	
	import spark.components.BorderContainer;
	import spark.components.Group;
	import spark.components.Label;
	import spark.layouts.HorizontalLayout;
	import spark.layouts.VerticalLayout;
	
	public class PropertyEditor extends Group
	{
		private var config:Array;
		public var props:Object;
		private var _elementId:Object;
		private var _elementType:int;
		private var _dataProvider:IPropEditableElement;
		
		public function PropertyEditor(elementType:int)
		{
			super();
			this._elementType = elementType;
			this.percentHeight = 100;
			this.percentWidth = 100;
			var vl:VerticalLayout = new VerticalLayout();
			vl.gap = 0;
			this.layout = vl;
			
			var bar:BorderContainer = new BorderContainer();
			bar.setStyle("backgroundColor", 0xDFE8DF);
			bar.percentWidth = 100;
			bar.height = 20;
			vl = new VerticalLayout();
			vl.horizontalAlign = "center";
			vl.verticalAlign = "middle";
			bar.layout = vl;
			var title:Label = new Label();
			title.text = "属性编辑";
			bar.addElement(title);
			this.addElement(bar);
			
			init();
		}
		
		public function set elementId(eleId:Object):void{
			this._elementId = eleId;
		}
		
		public function get elementId():Object{
			return this._elementId;
		}
		
		public function init():void{
			this.props = new Object();
			this.config = [];
			var notifyPattern:String = "尊敬的${userName}，${treatUserName}已完成了${processTitle}流程${taskName}步骤的处理";
			var promptPattern:String = "尊敬的${userName}，您有一条${processName}待处理";
			var boolList:Array = [{"value":"1","label":"是"},{"value":"0","label":"否"}];
			var rollbackList:Array = [{"value":"-1","label":"不允许"},{"value":"1","label":"强制"},{"value":"2","label":"等待"}];
			switch(this._elementType){
				case ElementType.TEMPLATE:
					this.config = [
						{"id" : "processKey", "title" : "流程标识", "type":PropertySelector.UUIDSELECTOR, "label":"", "value":""},
						{"id" : "processName", "title" : "流程名称", "type":PropertySelector.TEXT, "label":"", "value":""},
						{"id" : "custId", "title" : "流程站点", "type":PropertySelector.SITESELECTOR, "label":"", "value":""},
						{"id" : "form", "title" : "流程表单", "type":PropertySelector.FORMSELECTOR, "label":"", "value":""},
						{"id" : "notifyPattern", "title" : "通知消息", "type":PropertySelector.MESSAGEEDITOR, "label":notifyPattern, "value":""},
						{"id" : "promptPattern", "title" : "提醒消息", "type":PropertySelector.MESSAGEEDITOR, "label":promptPattern, "value":""}
					];
					break;
				case ElementType.START:
				case ElementType.END:
					this.config = [
						{"id" : "nodeKey", "title" : "节点标识", "type":PropertySelector.UUIDSELECTOR, "label":"", "value":""},
						{"id" : "nodeName", "title" : "节点名称", "type":PropertySelector.TEXT, "label":"", "value":""}
					];
					break;
				case ElementType.TASK:
					this.config = [
						{"id" : "nodeKey", "title" : "标识", "type":PropertySelector.UUIDSELECTOR, "label":"", "value":""},
						{"id" : "nodeName", "title" : "名称", "type":PropertySelector.TEXT, "label":"", "value":""},
						{"id" : "custId", "title" : "站点", "type":PropertySelector.SITESELECTOR, "label":"", "value":""},
						{"id" : "form", "title" : "绑定表单", "type":PropertySelector.FORMSELECTOR, "label":"", "value":""},
						{"id" : "visibleFormItems", "title" : "表单可见字段", "type":PropertySelector.FORMITEMSELECTOR, "label":"", "value":""},
						{"id" : "useableFormItems", "title" : "表单可用字段", "type":PropertySelector.FORMITEMSELECTOR, "label":"", "value":""},
						{"id" : "countersign", "title" : "是否会签", "type":PropertySelector.LIST, "label":"否", "value":"0", "list":boolList},
						{"id" : "superiorUserExec", "title" : "默认上级执行", "type":PropertySelector.LIST, "label":"否", "value":"0", "list":boolList},
						{"id" : "execRoles", "title" : "设置执行角色", "type":PropertySelector.ROLESELECTOR, "label":"", "value":""},
						{"id" : "execUsers", "title" : "设置执行人员", "type":PropertySelector.USERSELECTOR, "label":"", "value":""},
						{"id" : "execDepts", "title" : "设置执行部门", "type":PropertySelector.DEPTSELECTOR, "label":"", "value":""},
						{"id" : "showDefault", "title" : "显示执行人", "type":PropertySelector.LIST, "label":"否", "value":"0", "list":boolList},
						{"id" : "allowSelect", "title" : "允许交互", "type":PropertySelector.LIST, "label":"是", "value":"1", "list":boolList},
						{"id" : "rollbackType", "title" : "回退方式", "type":PropertySelector.LIST, "label":"强制", "value":"1", "list":rollbackList},
						{"id" : "notifyPattern", "title" : "通知消息", "type":PropertySelector.MESSAGEEDITOR, "label":"", "value":""},
						{"id" : "promptPattern", "title" : "提醒消息", "type":PropertySelector.MESSAGEEDITOR, "label":"", "value":""}						
					];					
					break;
				case ElementType.PROC:
					this.config = [
						{"id" : "nodeKey", "title" : "标识", "type":PropertySelector.UUIDSELECTOR, "label":"", "value":""},
						{"id" : "nodeName", "title" : "名称", "type":PropertySelector.TEXT, "label":"", "value":""},
						{"id" : "custId", "title" : "站点", "type":PropertySelector.SITESELECTOR, "label":"", "value":""},
						{"id" : "subProc", "title" : "子流程", "type":PropertySelector.TEMPLATESELECTOR, "label":"", "value":""}			
					];						
					break;
				case ElementType.LINK:
					this.config = [
						{"id" : "linkKey", "title" : "标识", "type":PropertySelector.UUIDSELECTOR, "label":"", "value":""}			
					];						
					break;
				default:
					break;
			}
			for(var i:int = 0; i < this.config.length; i++){
				var one:Object = this.config[i];
				var prop:PropertyObject = new PropertyObject(this);
				prop.id = one["id"];
				prop.type = one["type"];
				prop.title = one["title"];
				prop.setDataProvider(one["list"]);
				prop.setValue(one["value"], one["label"]);
				this.props[prop.id] = prop;
				this.addElement(prop);
			}
		}
		
		public function get dataProvider():IPropEditableElement{
			return this._dataProvider;
		}
		
		public function set dataProvider(data:IPropEditableElement):void{
			this._dataProvider = data;
		}
	}
}